#index的views.py的myvariable函数
from django.views.generic import ListView,DetailView,FormView,CreateView,UpdateView,DeleteView,MonthArchiveView,WeekArchiveView
from .models import PersonInfo
from django.urls import reverse_lazy
from .forms import PostForm
from django.http import HttpResponse

def result(request):
    return HttpResponse('good job')
class index1(ListView):
    template_name = 'index1.html'
    extra_context = {'title':'人员信息表'}
    queryset = PersonInfo.objects.all()
    paginate_by = 1

class index2(DetailView):
    template_name = 'index2.html'
    extra_context = {'title':'人员信息表'}
    slug_field = 'age'
    slug_url_kwarg = 'age'
    pk_url_kwarg = 'pk'
    model = PersonInfo
    
class index3(FormView):
    template_name = 'index3.html'
    form_class = PostForm
    success_url = "/result"

    def form_valid(self, form):
        form.save()
        return super().form_valid(form)

class index4(CreateView):
    model = PersonInfo
    template_name = "index3.html"
    form_class = PostForm
    success_url ="/result"

class index5(UpdateView):
    model = PersonInfo
    template_name = "index3.html"
    form_class = PostForm
    success_url = "/result"

class index6(DeleteView):
    model = PersonInfo
    template_name = "index4.html"
    success_url ="/result"

class index7(MonthArchiveView):
    allow_empty = True
    allow_future = True
    context_object_name = 'mylist'
    template_name = 'index5.html'
    model = PersonInfo
    date_field = 'hireDate'
    queryset = PersonInfo.objects.all()
    year_format = '%Y'
    #month_format默认值为%b，支持英文日期，如Oct
    month_format = '%m'
    paginate_by = 50

class index8(WeekArchiveView):
    allow_empty = True
    allow_future = True
    context_object_name = 'mylist'
    template_name = 'index6.html'
    model = PersonInfo
    date_field = 'hireDate'
    queryset = PersonInfo.objects.all()
    year_format = '%Y'
    week_format = '%W'
    paginate_by = 50


